package com.market.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

/**
 * 生成随机数
 *
 * @author 2731235517@qq.com 谢畅
 * @since 2022/12/29 12:57
 */

public class RandomUtil {
    private static Random random=new Random();

    public static String newLocalFileName() {
        StringBuffer stringBuffer = new StringBuffer();
        String str = "abcdefghijklmnopqrstuvwxyz0123456789";
        for (int j = 0; j < 20; j++) {
            stringBuffer.append(str.charAt(random.nextInt(str.length())));
        }
        return stringBuffer.toString();
    }


    public static String newOrderSn() {
        String format = new SimpleDateFormat("yyyyMMdd").format(new Date());
        StringBuffer stringBuffer = new StringBuffer(format);
        String str = "0123456789";
        for (int j = 0; j < 6; j++) {
            stringBuffer.append(str.charAt(random.nextInt(str.length())));
        }
        return stringBuffer.toString();
    }

    //生成随机的优惠卷兑换码
    public static String couponCode() {
        StringBuffer stringBuffer = new StringBuffer();
        String str = "QWERTYUIPASDFGHJKLZXCVBNM123456789";
        for (int j = 0; j < 8; j++) {
            stringBuffer.append(str.charAt(random.nextInt(str.length())));
        }
        return stringBuffer.toString();
    }

}
